<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\PunchCardUser;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class PunchCardUserController extends AdminController
{
    public $title = '用户列表';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new PunchCardUser(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->openid;
            $grid->nickname;
            $grid->name->editable();
            $grid->avatar->image('',50,50);
            $grid->column('punch_num');
            $grid->created_at;
            $grid->updated_at->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('nickname');
                $filter->between('created_at', '创建时间')->datetime();
        
            });
            $grid->showQuickEditButton();
            $grid->disableCreateButton();
            $grid->model()->orderBy('id', 'desc');
            $grid->export();
        //    $grid->withBorder();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new PunchCardUser(), function (Show $show) {
            $show->id;
            $show->openid;
            $show->nickname;
            $show->avatar->image('',50,50);
            $show->punch_num;
            $show->created_at;
            $show->updated_at;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new PunchCardUser(), function (Form $form) {
            $form->display('id');
            $form->display('openid');
            $form->display('nickname');
            // $form->display('avatar')->image('avatar');
            $form->text('name');
            $form->text('punch_num');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
